<!-- Horizontal Form -->
<div class="box box-info">
	<div class="box-header with-border">
		<!--原user_edit页面 -->
		<h3 class="box-title">添加商品信息</h3>
		<h5 class="msg"></h5>
	</div>
	<!-- /.box-header -->
	<!-- form start -->
	<form class="form-horizontal" style="">
		<div class="box-body">
			<div class="form-group">
				<label for="usernameId" class="col-sm-2 control-label">分类名称名</label>
				<div class="col-sm-10">
					<select id="selectGategoryName" class="form-control pull-right"
						style="height: 40px;" required="required">
					</select>
				</div>
			</div>
			<div class="form-group">
				<label for="passwordId" class="col-sm-2 control-label">商品名称</label>
				<div class="col-sm-10">
					<input type="text" class="form-control" id="goodsName" required="required"/>
				</div>
			</div>
			<div class="form-group" id="pwdDiv">
				<label for="passwordId" class="col-sm-2 control-label">商品描述</label>
				<div class="col-sm-10">
					<input type="text" class="form-control" id="passwordId"
						style="height: 80px;">
				</div>
			</div>
			<div class="form-group">
				<label for="passwordId" class="col-sm-2 control-label">商品价格</label>
				<div class="col-sm-10">
					<input type="text" class="form-control" id="goodsPrice">
				</div>
			</div>
			<div class="form-group">
				<label for="emailId" class="col-sm-2 control-label">商品状态</label>
				<div class="col-sm-10">
					<select id="selectStatus" style="height: 30px;">
						<option value='0'>下架</option>
						<option value='1'>上架</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label for="emailId" class="col-sm-2 control-label">排序</label>
				<div class="col-sm-10">
					<input type="text" class="form-control" id="emailId">
				</div>
			</div>
			<div class="form-group">
				<label for="emailId" class="col-sm-2 control-label">商品图片</label>
				<div class="col-sm-10">
					<input type="text" class="form-control" id="goodsLogo">
				</div>
			</div>
		</div>
			<!-- /.box-body -->
			<div class="box-footer">
				<button type="button" class="btn btn-default btn-cancel">取消</button>
				<button type="button" class="btn btn-info pull-right btn-save">确定添加</button>
				<!-- <a href="../starter.html" target="_blank">测试超链接</a> -->
			</div>
			<!-- /.box-footer -->
	</form>
	<!-- <div class="layui-layer layui-layer-page layui-layer-molv layer-anim"
		id="treeLayer" type="page" times="2" showtime="0" contype="object"
		style="z-index: 59891016; width: 300px; height: 450px; top: 100px; left: 500px; display: none">
		<div class="layui-layer-title" style="cursor: move;">选择部门</div>
		<div class="layui-layer-content" style="height: 358px;">
			<div style="padding: 10px;" class="layui-layer-wrap">
				<ul id="zTreeId" class="ztree"></ul>
				动态加载树
			</div>
		</div>
		<span class="layui-layer-setwin"> <a
			class="layui-layer-ico layui-layer-close layui-layer-close1 btn-cancel"></a></span>
		<div class="layui-layer-btn layui-layer-btn-">
			<a class="layui-layer-btn0 btn-confirm">确定</a> <a
				class="layui-layer-btn1 btn-cancel">取消</a>
		</div>
	</div> -->
</div>
<!-- <script type="text/javascript"
	src="bower_components/ztree/jquery.ztree.all.min.js"></script> -->
<script type="text/javascript" src="validate/dist/jquery.validate.min.js"></script>
<script type="text/javascript" src="validate/dist/localization/messages_zh.js"></script>
<script type="text/javascript" src="bower_components/layer/layer.js"></script>
<script type="text/javascript">
	$.validator.setDefaults({
    	submitHandler: function() {
     	 /* alert("提交事件!"); */
    	}
	});
	$(document).ready(
			function() {
				//类目名下拉s选框
				doGetCategory();

				//事件注册
				$(".box-footer").on("click", ".btn-cancel", doCancel).on(
						"click", ".btn-save", doSaveOrUpdate);
				//$("form").on("blur", "#usernameId", isExists);
				/* $("#selectStatus").change(function() {
					alert($("select option:selected").text())
				}); */
				$(".form-horizontal").validate();
			});
	
	//类目名下拉选框
	function doGetCategory() {
		url = "goods/doLoadCategoryName";
		$.post(url, function(result) {
			if (result.status == 1) {
				doLoadCategoryName(result.data);
			} else {
				alert(result.message);
			}
		});
	}
	function doLoadCategoryName(category) {
		$("#selectGategoryName").append(
				"<option value='请选择商品类名'>请选择商品类名</option>");
		for (var i = 0; i < category.length; i++) {
			var name = category[i].categoryName;
			var id = category[i].id;
			$("#selectGategoryName").append(
					"<option id = '"+id+"' value='"+name+"'>" + name
							+ "</option>");
		}
	}

	function isExists() {
		var filedName = $(this).prop("name");
		var filedValue = $(this).val();
		var params = {
			"filedName" : filedName,
			"filedValue" : filedValue
		};
		var url = "user/isExists";
		$.getJSON(url, params, function(result) {
			if (result.data) {
				$(".msg").html(filedName + "已存在");
			} else {
				$(".msg").html(" ");
			}
		});
	}

	function doCancel() {
		//$("#mainContentId").removeData("rowData");
		$("#mainContentId").load("goods_list");
	}

	function doSaveOrUpdate() {
		/* var rowData = $("#mainContentId").data("rowData"); */
		//1.获取表单数据
		var params = doGetEditFormData();
		//2.发起异步请求
		console.log("params页面数据", params);
		var insertUrl = "goods/doSaveGoodsObject";
		$.post(insertUrl, params, function(result) {
			if (result.status == 1) {
				alert(result.message);
				doCancel();
			} else {
				alert(result.message);
			}
		})
	}

	function doGetEditFormData() {

		//获取用户输入的数据
		var params = {
			categoryId : $("#selectGategoryName option:selected").prop("id"),
			goodsName : $("#goodsName").val(),
			goodsDescription : $("#passwordId").val(),
			goodsPrice : $("#goodsPrice").val(),
			goodsStatus : $("#selectStatus option:selected").prop("value"),
			sort : $("#emailId").val(),
			goodsLogo : $("#goodsLogo").val()
		}
		console.log(params);
		return params;
	}
</script>






